import React from "react";
import Context from "./context";
import { isForm } from "../../constant/component-type";

class FormNode extends React.Component {
  renderItem = ({ form }) => {
    const { getFieldDecorator } = form;
    const { getData, children } = this.props;
    const column = getData("column");
    return getFieldDecorator(column)(
      <children.type {...children.props} form={form} />
    );
  };

  render() {
    return <Context.Consumer>{this.renderItem}</Context.Consumer>;
  }
}

export default {
  strategy(props) {
    const { node } = props;
    return isForm(node.type);
  },
  component: FormNode,
};
